﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using RBAC.Web.Service;
using RBAC.Web.Models;
namespace RBAC.Web.Mapper
{
    public class RoleUserMapper
    {
        public static RoleUserModel DtoToModel(RoleUserDto inputDto)
        {
            RoleUserModel result = new RoleUserModel();

            result.Id = inputDto.Id;
            result.CreateDate = inputDto.CreateDate;
            result.UpdateDate = inputDto.UpdateDate;
            result.UpdateBy = inputDto.UpdateBy;
            result.Version = inputDto.Version;

            if (inputDto.Role != null)
            {
                result.Role = inputDto.Role.Id;

                result.RoleRoleCode = inputDto.Role.RoleCode;

                result.RoleRoleName = inputDto.Role.RoleName;
            }

            if (inputDto.User != null)
            {
                result.User = inputDto.User.Id;

                result.UserUsername = inputDto.User.Username;

                result.UserEmail = inputDto.User.Email;
            }
            result.ProjectId = inputDto.ProjectId;

            return result;
        }


        public static RoleUserDto ModelToDto(RoleUserModel inputModel)
        {


            RoleUserDto result = new RoleUserDto();

            result.Id = inputModel.Id;
            result.CreateDate = inputModel.CreateDate.GetValueOrDefault();
            result.UpdateDate = inputModel.UpdateDate;
            result.UpdateBy = inputModel.UpdateBy;
            result.Version = inputModel.Version;
            if (inputModel.Role != 0)
            {
                result.Role = new RoleDto() { Id = inputModel.Role };
            }
            else
            {
                //result.Role = new RoleDto();
                result.Role = null;
            }

            if (inputModel.User != 0)
            {
                result.User = new UserDto() { Id = inputModel.User };
            }
            else
            {
                //result.User = new UserDto();
                result.User = null;
            }

            result.ProjectId = inputModel.ProjectId;

            return result;
        }

    }
}